Skip to content

Keep Search layer hidden when show=False - #2378

Open
vladosskins178 wants to merge 1 commit into
python-visualization:mainfrom
vladosskins178:fix/search-respect-layer-show
Open

vladosskins178 wants to merge 1 commit into
python-visualization:mainfrom
vladosskins178:fix/search-respect-layer-show

Conversation

@vladosskins178

Copy link
Copy Markdown

Fixes #2377

L.Control.Search adds its layer to the map when the control is added: onAdd calls setLayer(this._layer), and setLayer does this._layer.addTo(this._map) (leaflet-search 2.9.7 source). So a layer created with show=False became visible as soon as a Search control was attached to it, even though folium itself never added it.

This removes the layer again right after addControl when layer.show is False. Layers with show=True are unchanged.

Checked in headless Chrome with the issue's setup (a hidden GeoJson with a Search control, plus a shown GeoJson with its own Search control, and a LayerControl):

hidden layer on map at load shown layer on map at load
main true true
this branch false true

After switching the hidden layer on in the LayerControl, the search still finds its features.

Tests: two cases in tests/plugins/test_search.py (hidden layer is removed after the control is added; shown layer is not removed). The first one fails on main.

L.Control.Search adds its layer to the map in onAdd (setLayer calls
layer.addTo(map)), so a layer created with show=False became visible
as soon as a Search control was attached to it. Remove the layer again
right after the control is added when show is False.

Fixes python-visualization#2377

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Search Class Ignores "show" Argument.

1 participant